package com.btex.app.treaty;

import android.view.View;
import android.widget.TextView;

import com.btex.app.MyApplication;
import com.btex.app.R;
import com.btex.app.entity.PositionsInfo;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/20
 * @time 上午11:04
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class PositionsAdapter extends BaseQuickAdapter<PositionsInfo.DataBean.PositionListsBean, BaseViewHolder> {

    private String mDanwei;
    private String mNumbers = "8";

    public PositionsAdapter() {
        super(R.layout.item_positions_adapter);
    }

    @Override
    protected void convert(BaseViewHolder helper, PositionsInfo.DataBean.PositionListsBean item) {


        String ctime = item.getCtime();
        String mx_symbol = item.getMx_symbol();
        String rlz_pnl = item.getRlz_pnl();
        String pst_status = item.getPst_status();


        View item_positions_view_type = helper.getView(R.id.item_positions_view_type);
        TextView item_positions_tv_price = (TextView) helper.getView(R.id.item_positions_tv_price);
        TextView item_positions_tv_time = (TextView) helper.getView(R.id.item_positions_tv_time);
        TextView item_positions_tv_name = (TextView) helper.getView(R.id.item_positions_tv_name);

//        if (pst_status.equals("1")) {
//            item_positions_view_type.setBackgroundResource(R.color.red);
//        } else {
//            item_positions_view_type.setBackgroundResource(R.color.bg_green);
//        }

        String timedate = Tools.timedate(ctime);


        item_positions_tv_name.setText(mx_symbol);
        item_positions_tv_time.setText(timedate);

        String trim = Tools.round(Double.valueOf(rlz_pnl), Integer.valueOf(mNumbers)).toString().trim();

        item_positions_tv_price.setText(trim + "\t" + "\t" + mDanwei);

        Double aDouble = Double.valueOf(rlz_pnl);
        if (aDouble < 0) {
            item_positions_view_type.setBackgroundResource(R.color.red);
            item_positions_tv_price.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.red));
        } else {
            item_positions_view_type.setBackgroundResource(R.color.bg_green);
            item_positions_tv_price.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.bg_green));
        }


    }

    public void setDanwei(String danwei) {

        mDanwei = danwei;
    }

    public void setNumber(String numbers) {

        mNumbers = numbers;
    }
}
